package pe.edu.upc.jtigers.svpn.data.implement;

import org.springframework.stereotype.Repository;
import pe.edu.upc.jtigers.svpn.aplication.excepcion.DAOExcepcion;
import pe.edu.upc.jtigers.svpn.data.common.BaseDao;
import pe.edu.upc.jtigers.svpn.domain.data.SabioDao;
import pe.edu.upc.jtigers.svpn.domain.model.Sabio;

@Repository
public class SabioDaoImpl extends BaseDao<Sabio> implements SabioDao {

	@Override
	public Sabio registrarSabio(Sabio sabio) throws DAOExcepcion {
		try {
			if (sabio.getIdUsuario() == 0) {
				entityManager.persist(sabio);
			} else {
				entityManager.merge(sabio);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new DAOExcepcion(e);
		}
		return sabio;
	}

	@Override
	public Sabio obtenerSabio(int idSabio) throws DAOExcepcion {
		try {
			return entityManager.find(Sabio.class, idSabio);
		} catch (Exception e) {
			throw new DAOExcepcion(e);
		}
	}

}
